package org.dwell.nutzcow.module;

import org.dwell.nutzcow.domain.FileResource;
import org.dwell.nutzcow.test.FileResourceDB;
import org.nutz.json.Json;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by Jange on 2016/3/30.
 */
public class MainModule {

    @At("/hello")
    @Ok("jsp:jsp.hello")
    public String hello() {
        return "Hello Nutz";
    }

    @At("/treetable")
    @Ok("jsp:jsp.treetable")
    public void treetable(HttpServletRequest request) {
        request.setAttribute("fileNodes", FileResourceDB.getTops());
    }
    @At("/jqtreegrid")
    @Ok("jsp:jsp.jgGrid-tree")
    public void jqtreegrid(HttpServletRequest request) {

    }

    @At("/nodes/children/find")
    @Ok("json")
    public String children(@Param("id") String id) {
        List<FileResource> resources = FileResourceDB.getChildren(id);
        return Json.toJson(resources);
    }
}
